package com.jcl.recruit.console.elastic.logic;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jcl.core.common.page.PageResult;
import com.jcl.recruit.elasticsearch.resume.dao.ConsoleSearchResumeDao;
import com.jcl.recruit.elasticsearch.resume.model.ConsoleSearchResume;
import com.jcl.recruit.elasticsearch.resume.vo.ElasticPageCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

import static org.springframework.beans.support.PagedListHolder.DEFAULT_PAGE_SIZE;

/**
 * @ClassName ConsoleElasticResumeLogic
 * @Author yyliu
 * @Date 2018/12/24 17:08
 * @Version 1.0
 **/
@Component
public class ConsoleElasticResumeLogic {
    @Autowired
    private ConsoleSearchResumeDao consoleSearchResumeDao;

    public PageResult pageResult(ElasticPageCondition condition,
                                 Integer curPage,
                                 Integer rowSize) {
        curPage = null == curPage ? 1 : rowSize;
        rowSize = null == rowSize ? DEFAULT_PAGE_SIZE : rowSize;
        PageHelper.startPage(curPage, rowSize);
        List<ConsoleSearchResume> list = consoleSearchResumeDao.findList(condition);
        PageInfo info = new PageInfo(list);
        return new PageResult(curPage, rowSize, info.getTotal(), info.getList());


    }
}
